package com.rd.student.jiaji.class3.caiyuxin.java8_8;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) throws IOException {
        //用户输入信息
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学生姓名：");
        String name = scanner.next();
        System.out.println("请输入" + name + "的语文成绩");
        int math = scanner.nextInt();
        System.out.println("请输入" + name + "的数学成绩");
        int chinese = scanner.nextInt();

        int total = math + chinese;

        System.out.println("添加成功");
//写入数据
//        File stu=new File("Student.txt");
//        OutputStream os=new FileOutputStream(stu);
//        byte[] nameb=name.getBytes(StandardCharsets.UTF_8);
//        os.write(nameb);
        RandomAccessFile raf = new RandomAccessFile("Student.txt", "rw");
        long fileLength = raf.length();
        raf.seek(fileLength);
        byte[] nameb = name.getBytes(StandardCharsets.UTF_8);
        raf.writeBytes("\n");
        raf.write(nameb);
        raf.writeBytes(" " + chinese);
        raf.writeBytes(" " + math);
        raf.writeBytes(" " + total);
        raf.close();
    }
}
